/**
 * Copyright (c) Software Institute of PKU
 * All rights reserved. 
 * This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 */
package edu.pku.sei.modeler.commands;

import org.eclipse.gef.commands.Command;

import edu.pku.sei.modeler.model.structure.MetaBendPoint;
import edu.pku.sei.modeler.model.structure.MetaLink;

/**
 * @author zl
 *
 */
public class DeleteBendpointCommand extends Command {
	private MetaLink link;
	private MetaBendPoint bendpoint;
	private int index;

	public DeleteBendpointCommand(MetaLink link, int index) {
		super("Delete Bendpoint");
		this.link = link;
		this.index = index;
		bendpoint = (MetaBendPoint)link.getBendPoints().get(index);
	}

	public boolean canExecute() {
		return index >= 0 && bendpoint != null && link != null;
	}
		
	public void execute() {
		link.getBendPoints().remove(index);
	}

	public void undo() {
		link.getBendPoints().add(index, bendpoint);
	}
}
